package cn.javaxc.mvcwork.framework.database;
import java.util.*;
import java.sql.*;
import javax.sql.*;
import javax.servlet.ServletContext;
import org.springframework.beans.factory.annotation.Autowired;


public class DataSourcePool implements ConnectionPool,org.springframework.web.context.ServletContextAware{ 

	@Autowired
	private DataSource dataSource;
	public DataSource getDataSource(){
		return this.dataSource;
	}
	public void setDataSource(DataSource dataSource){
		this.dataSource=dataSource;
	}
	public void init(Map<String,String> prefs){

	}
	public void setServletContext(ServletContext context) {
		cn.javaxc.mvcwork.controller.MVCConfig.getConfig().setConnectionPool(this);
		context.setAttribute("ConnectionPool",this);
	}
	public Connection getConnection() throws SQLException{
		return dataSource.getConnection();
	}
	public Connection getConnection(ConnectionElement ce) throws SQLException{
		return dataSource.getConnection();
	}
	  public void free(Connection db) {
		if (db != null) {
			try{
				db.close();
			}catch(SQLException e){
				e.printStackTrace();
			}		  
		}
		db = null;
	  }
	public void closeAllConnections(){
	}	
	public String toString(){
		return dataSource.toString();
	}
}
